package com.zelin.gateway.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;

/**
 * Created by WF on 2020/8/1 7:43
 * 使用配置的方式定义路由规则
 */
@Configuration
public class SpringGatewayConfig {
    @Bean
    public RouteLocator customerRouteLocator(RouteLocatorBuilder rb){
        // RouteLocatorBuilder.Builder routes = rb.routes();
        // RouteLocator routeLocator = routes.route(r -> r.path("/stud/**").uri("lb://tensquare-base")).build();
        //return routeLocator;
        //定义一个路由规则
        return rb.routes().route("route_path2",r -> r.path("/stud/**").uri("lb://tensquare-base"))
                   .build();
    }
}
